﻿using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XWeb.WebApi.App
{
    [PostAction("user", "login", "1.0")]
    public class LoginAction : BaseAction<LoginParams, LoginResult>
    {
        protected override ActionResult<LoginResult> OnExecute(ActionContext context, SysParams sysParams, LoginParams opParams)
        {
            LoginResult actResult = new LoginResult();
            if(string.Equals(opParams.Account, "admin") && string.Equals(opParams.Password, "1"))
            {
                CPPEI.WebApi.Config.Current.AuthProvider.Save("admin", TimeSpan.FromHours(24));
                actResult.UserId = "admin";
                return new ActionResult<LoginResult>(actResult);
            }
            return new ActionResult<LoginResult>(new CPPEI.ServiceResult(0));
        }
    }

    public class LoginParams
    {
        public string Account{get;set;}
        public string Password{get;set;}
    }

    public class LoginResult
    {
        public string UserId { get; set; }
    }
}
